package com.example.springdemo;

import com.example.springdemo.controller.WelcomeController;
import com.example.springdemo.service.WelcomeService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.FileSystemXmlApplicationContext;


@Configuration
@ComponentScan("com.example.springdemo")
public class Entrance {
	public static void mainXml(String[] args) {
		System.out.println("Hello World!");
		String xmlPath = "D:\\projects\\IdeaProject\\spring-framework-5.2.10.RELEASE\\spring_demo\\src\\main\\resources\\spring\\spring-config.xml";
		ApplicationContext applicationContext = new FileSystemXmlApplicationContext(xmlPath);
		 WelcomeService welcomeService = (WelcomeService)applicationContext.getBean("welcomeService");
		 welcomeService.sayHello("强大的spring框架");
	}

	public static void main(String[] args) {
		ApplicationContext applicationContext = new AnnotationConfigApplicationContext(Entrance.class);
		String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
		for(String beanDefinitionName: beanDefinitionNames) {
			System.out.println(beanDefinitionName);
		}
		WelcomeController welcomeController = (WelcomeController)applicationContext.getBean("welcomeController");
		welcomeController.handleRequest();
	}

}
